#ifndef _FILTER_CONTROL_
#define _FILTER_CONTROL_

#include <streams.h>
#include <strmif.h>
#include "DEQ.H"
#include "../../Filters/TCCDEQFilter/TCCPWSInterface.h"

static const GUID CLSID_TCCVREND =
{ 0xcd0fb4f0, 0x69f3, 0x4fa5, { 0xb4, 0x2a, 0x8, 0xdc, 0x41, 0x51, 0x6b, 0x3a } };


#if !defined (SAFE_RELEASE)
#define SAFE_RELEASE(x)	if(x){x->Release(); x=NULL;}
#endif

#if !defined (SAFE_REMOVE_FILTER)
#define SAFE_REMOVE_FILTER(x, y)  if (x && y) { y->RemoveFilter(x); SAFE_RELEASE(x); }
#endif

struct VrenderModeFlag{
	unsigned int mode; 
	// 0: default(no alpha blending & no croma key)
	// 1: chroma key(using xCHValue)
	// 2: alpha blending 25%
	unsigned int left;
	unsigned int top;
	unsigned int width;
	unsigned int height;
	unsigned int reserved[5];
};
//adf85a65-358f-4fcd-86b1-b8f3d6540324
static const GUID IID_ITccVren = 
{ 0xadf85a65, 0x358f, 0x4fcd, {0x86, 0xb1, 0xb8, 0xf3, 0xd6, 0x54, 0x03, 0x24} };

DECLARE_INTERFACE_(ITccVren, IUnknown)
{
	STDMETHOD(GetModeFlag)(THIS_ VrenderModeFlag* Flag) PURE;
	STDMETHOD(SetModeFlag)(THIS_ VrenderModeFlag Flag) PURE;
	STDMETHOD(SetAVSync)(THIS_ BOOL bAVSync) PURE;	
	STDMETHOD(SetM2MScaler)(THIS_ BOOL bM2MScaler) PURE;
	STDMETHOD(SetAlphaBlanding)(THIS_ BOOL AlphaBlanding) PURE;
};

class CFilterControl {

public:
	CFilterControl(void);
	~CFilterControl(void);
	int CreateFilterGraph(void);
	void DestroyFilterGraph(void);

	void DeleteFiltersForPlaying(void);
	BOOL GetPlayDuration(double *duration);
	BOOL GetCurrentPlayTime(double *Pos);

	int CreateFilterForPlaying(TCHAR *FileName);
	BOOL SetCurrentPlayTime(double pos);

	void SetDEQMode(DEQDynamicFlag dflag);

	BOOL RunGraph();
	BOOL StopGraph();
	BOOL PauseGraph();
	BOOL IsRunning(){ return mIsRunning;}
	void GetPWSBand(int *pPWSBand,int MaxBandNum);
	void SetPWSOnOff(BOOL bOnOff);
	BOOL SetAudioVolume(unsigned int AudioVolume);
	BOOL GetAudioVolume(unsigned int* pAudioVolume);

protected:
	bool mIsRunning;

	IGraphBuilder *mpGraph;
	IBaseFilter   *m_pDEQFilter;

	VrenderModeFlag Rendererflag;

	BOOL CheckCoCreateInstance(HRESULT &hr, REFCLSID rclsid, REFIID riid, LPVOID* ppv, LPCTSTR pszErrorMessage);
	BOOL AddFilterForRecording(void);
	BOOL AddFilterForCapture(void);
	BOOL RemoveFilter(void);
	BOOL Disconnect(IBaseFilter *pBaseFilter, LPCTSTR pszPinName, PIN_DIRECTION Dir);

	BOOL CheckConnect(HRESULT &hr, IBaseFilter *pBaseFilterUpstream, LPCTSTR pszOutpinName, IBaseFilter *pBaseFilterDownstream, LPCTSTR pszInpinName, LPCTSTR pszErrorMessage);
//	static HRESULT FindPin(IBaseFilter *pFilter, PIN_DIRECTION Dir, LPCTSTR pszPinName, IPin **ppPin);
};

#endif